# 代码结果：
    # IPhone launched
    # MacBook launched
    # MIPhone launched
    # MIBook launched

from abc import ABC, abstractmethod

# 抽象产品类
class Computer(ABC):
    @abstractmethod
    def launch(self):
        pass

class Phone(ABC):
    @abstractmethod
    def launch(self):
        pass

# 具体产品类
class MacBook(Computer):
    def launch(self):
        print("MacBook launched")

class MIBook(Computer):
    def launch(self):
        print("MIBook launched")

class IPhone(Phone):
    def launch(self):
        print("IPhone launched")

class MIPhone(Phone):
    def launch(self):
        print("MIPhone launched")

# 抽象工厂类
class AbstractFactory(ABC):
    @abstractmethod
    def phone(self) -> Phone:
        pass

    @abstractmethod
    def computer(self) -> Computer:
        pass

# 具体工厂类
class AppleFactory(AbstractFactory):
    def phone(self) -> Phone:
        return IPhone()

    def computer(self) -> Computer:
        return MacBook()

class MiFactory(AbstractFactory):
    def phone(self) -> Phone:
        return MIPhone()

    def computer(self) -> Computer:
        return MIBook()

# 客户端代码
class Client:
    def __init__(self, factory: AbstractFactory):
        self.factory = factory

    def get_phone(self) -> Phone:
        return self.factory.phone()

    def get_computer(self) -> Computer:
        return self.factory.computer()

# 客户端使用示例
if __name__ == "__main__":
    # 使用 Apple 工厂
    apple_factory = AppleFactory()
    apple_client = Client(apple_factory)
    apple_phone = apple_client.get_phone()
    apple_computer = apple_client.get_computer()
    apple_phone.launch()
    apple_computer.launch()

    # 使用 Mi 工厂
    mi_factory = MiFactory()
    mi_client = Client(mi_factory)
    mi_phone = mi_client.get_phone()
    mi_computer = mi_client.get_computer()
    mi_phone.launch()
    mi_computer.launch()